home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / mail / mailx6 / _setup.1 / MAIN2.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-19  |  8.0 KB  |  321 lines

  1. unit Main2;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Grids, Outline, ExtCtrls, TabNotBk,
  8.   MXMAILX;
  9.  
  10. {$I mailxdef.int}
  11.  
  12. type
  13.   TDemoForm = class(TForm)
  14.     Tab: TTabbedNotebook;
  15.     Panel1: TPanel;
  16.     Panel2: TPanel;
  17.     Outline1: TOutline;
  18.     btnScan: TButton;
  19.     btnRecipient: TButton;
  20.     btnFiles: TButton;
  21.     btnMessage: TButton;
  22.     Label1: TLabel;
  23.     Label2: TLabel;
  24.     Label3: TLabel;
  25.     Label4: TLabel;
  26.     Label5: TLabel;
  27.     szNotePart: TMemo;
  28.     szSubject: TEdit;
  29.     szFrom: TEdit;
  30.     szTime: TEdit;
  31.     btnReply: TButton;
  32.     btnForward: TButton;
  33.     btnSend: TButton;
  34.     FileGrid: TStringGrid;
  35.     Label6: TLabel;
  36.     Label7: TLabel;
  37.     ReciGrid: TStringGrid;
  38.     szResolve: TEdit;
  39.     BtnResolve: TButton;
  40.     BtnAdd: TButton;
  41.     btnAddress: TButton;
  42.     btnSignOn: TButton;
  43.     szCount: TLabel;
  44.     szStatus: TLabel;
  45.     MXForm1: TMXForm;
  46.     MXSession1: TMXSession;
  47.     MXMessage1: TMXMessage;
  48.     MXMessage2: TMXMessage;
  49.     MXRecipient1: TMXRecipient;
  50.     MXFile1: TMXFile;
  51.     procedure btnSignOnClick(Sender: TObject);
  52.     function IsActiveSession:Boolean;
  53.     procedure RefreshContainer;
  54.     procedure Outline1DblClick(Sender: TObject);
  55.     procedure btnScanClick(Sender: TObject);
  56.     procedure btnMessageClick(Sender: TObject);
  57.     procedure btnRecipientClick(Sender: TObject);
  58.     procedure btnFilesClick(Sender: TObject);
  59.     procedure FormCreate(Sender: TObject);
  60.     procedure RefreshReciGrid;
  61.     procedure BtnResolveClick(Sender: TObject);
  62.     procedure BtnAddClick(Sender: TObject);
  63.     procedure btnAddressClick(Sender: TObject);
  64.     procedure ReciGridDblClick(Sender: TObject);
  65.     procedure btnReplyClick(Sender: TObject);
  66.     procedure btnForwardClick(Sender: TObject);
  67.     procedure btnSendClick(Sender: TObject);
  68.     procedure ClearInboxList;
  69.     procedure RefreshFileGrid;
  70.   private
  71.     { Private declarations }
  72.   public
  73.     { Public declarations }
  74.   end;
  75.  
  76. var
  77.   DemoForm: TDemoForm;
  78.  
  79. implementation
  80.  
  81. {$R *.DFM}
  82. uses mailsys4;
  83.  
  84. procedure TDemoForm.btnSignOnClick(Sender: TObject);
  85. begin
  86.      MXSession1.Logon:=TRUE;
  87.      if IsActiveSession then
  88.      begin
  89.           szStatus.caption:='Active Session Available';
  90.           RefreshContainer;
  91.      end
  92.      else
  93.      begin
  94.           szStatus.caption:='NO Active Session Available';
  95.           szCount.caption:='';
  96.           ClearInboxList;
  97.      end;
  98. end;
  99.  
  100. procedure TDemoForm.RefreshContainer;
  101. var
  102.    PData: PString;
  103. begin
  104.      szCount.caption:=IntToStr(MXMessage1.MsgCount);
  105.      ClearInboxList;
  106.      Outline1.AddChild(0,'Inbox');
  107.  
  108.      MXMessage1.Action:= ACTION_FINDFIRST;
  109.      While MXMessage1.FetchMsg <> 0 Do
  110.      begin
  111.           PData:=NewStr(MXMessage1.MsgID);
  112.           Outline1.AddChildObject(1,MXMessage1.Subject,PData);
  113.           MXMessage1.Action:= ACTION_FINDNEXT;
  114.      end;
  115.      Tab.PageIndex:=0;
  116. end;
  117.  
  118. procedure TDemoForm.ClearInboxList;
  119. var
  120.    PData: PString;
  121.    Index: Integer;
  122. begin
  123.      Outline1.BeginUpdate;
  124.      for Index:=2 to Outline1.ItemCount do
  125.      begin
  126.         PData:=Outline1.Items[Index].Data;
  127.         if PData<> nil then
  128.         begin
  129.              DisposeStr(PData);
  130.         end;
  131.      end;
  132.      Outline1.Clear;
  133.      Outline1.EndUpdate;
  134. end;
  135.  
  136. function TDemoForm.IsActiveSession:Boolean;
  137. begin
  138.      if MXSession1.Logon=true then Result:=true
  139.      else
  140.      begin
  141.           Result:=false;
  142.           Application.MessageBox('No Active Session available',
  143.                                  'Mail eXtension DEMO for DELPHI',
  144.                                  MB_ICONSTOP);
  145.      end;
  146. end;
  147.  
  148. procedure TDemoForm.Outline1DblClick(Sender: TObject);
  149. var
  150.    x: PString;
  151.    y:string;
  152.    Index: Integer;
  153. begin
  154.    if Outline1.SelectedItem>1 then
  155.    begin
  156.         x:=Outline1.Items[Outline1.SelectedItem].Data;
  157.         MXMessage2.MsgID:=x^;
  158.         szSubject.text:=MXMessage2.Subject;
  159.         szNotePart.Lines:=MXMessage2.NoteText;
  160.         szTime.Text:=MXMessage2.TimeReceived;
  161.  
  162.         MXRecipient1.FetchType:=ftORIGINATOR;
  163.         MXRecipient1.FetchRecipient:=TRUE;
  164.         szFrom.Text:=MXRecipient1.RecipientName;
  165.  
  166.         MXRecipient1.FetchType:=ftRECIPIENTS;
  167.         MXRecipient1.FetchRecipient:=TRUE;
  168.         RefreshReciGrid;
  169.         MXFile1.FetchFile:=TRUE;
  170.         RefreshFileGrid;
  171.         Tab.PageIndex:=3;
  172.    end;
  173. end;
  174.  
  175. procedure TDemoForm.RefreshFileGrid;
  176. var
  177.    Index: integer;
  178. begin
  179.      FileGrid.RowCount:=MXFile1.FileCount;
  180.  
  181.      for Index:=0 to MXFile1.FileCount-1 do
  182.      begin
  183.           MXFile1.FileNum:=Index+1;
  184.           FileGrid.Cells[0,Index]:=MXFile1.FileName;
  185.           FileGrid.Cells[1,Index]:=MXFile1.FilePath;
  186.      end;
  187. end;
  188.  
  189. procedure TDemoForm.RefreshReciGrid;
  190. var
  191.    Index: integer;
  192. begin
  193.      ReciGrid.RowCount:=MXRecipient1.RecipientCount;
  194.  
  195.      for Index:=0 to MXRecipient1.RecipientCount-1 do
  196.      begin
  197.           MXRecipient1.RecipientNum:=Index+1;
  198.           ReciGrid.Cells[0,Index]:=MXRecipient1.RecipientName;
  199.           ReciGrid.Cells[1,Index]:=MXRecipient1.RecipientAddress;
  200.      end;
  201. end;
  202.  
  203. procedure TDemoForm.btnScanClick(Sender: TObject);
  204. begin
  205.      if IsActiveSession then RefreshContainer;
  206. end;
  207.  
  208. procedure TDemoForm.btnMessageClick(Sender: TObject);
  209. begin
  210.      Tab.PageIndex:=3;
  211. end;
  212.  
  213. procedure TDemoForm.btnRecipientClick(Sender: TObject);
  214. begin
  215.      Tab.PageIndex:=1;
  216. end;
  217.  
  218. procedure TDemoForm.btnFilesClick(Sender: TObject);
  219. begin
  220.      Tab.PageIndex:=2;
  221. end;
  222.  
  223. procedure TDemoForm.FormCreate(Sender: TObject);
  224. var
  225.    MailSystem: TMailSystem;
  226. begin
  227.      MailSystem:=TMailSystem.Create(Self);
  228.      MailSystem.ShowModal;
  229.      MailSystem.free;
  230.      ReciGrid.ColWidths[0]:=100;
  231.      ReciGrid.ColWidths[1]:=200;
  232.      ReciGrid.RowCount:=0;
  233. end;
  234.  
  235. procedure TDemoForm.BtnResolveClick(Sender: TObject);
  236. begin
  237.      if IsActiveSession then
  238.      begin
  239.           MXRecipient1.ResolveName:=szResolve.Text;
  240.           szResolve.Text:=MXRecipient1.ResolveName;
  241.      end;
  242. end;
  243.  
  244. procedure TDemoForm.BtnAddClick(Sender: TObject);
  245. begin
  246.      if IsActiveSession then
  247.      begin
  248.           MXRecipient1.Action:=ACTION_ADDRECIPIENT;
  249.           RefreshReciGrid;
  250.      end;
  251. end;
  252.  
  253. procedure TDemoForm.btnAddressClick(Sender: TObject);
  254. begin
  255.      if IsActiveSession then
  256.      begin
  257.           MXRecipient1.Action:=ACTION_ADDRESS;
  258.           RefreshReciGrid;
  259.      end;
  260. end;
  261.  
  262. procedure TDemoForm.ReciGridDblClick(Sender: TObject);
  263. var
  264.    rect: TGridRect;
  265. begin
  266.      if IsActiveSession then
  267.      begin
  268.           rect:=ReciGrid.Selection;
  269.           MXRecipient1.RecipientNum:=rect.top+1;
  270.           MXRecipient1.Action:=ACTION_DETAILS;
  271.      end;
  272. end;
  273.  
  274. procedure TDemoForm.btnReplyClick(Sender: TObject);
  275. begin
  276.      if IsActiveSession then
  277.      begin
  278.         MXMessage2.Action:= ACTION_REPLY;
  279.         MXMessage2.Action:= ACTION_SENDMSG;
  280.         If MXMessage2.ErrorNum <> 0 Then
  281.         begin
  282.             Application.MessageBox ('Unable to Send Message',
  283.                                    'Mail eXtension v1.51',
  284.                                    MB_ICONSTOP);
  285.         end;
  286.      end;
  287. end;
  288.  
  289. procedure TDemoForm.btnForwardClick(Sender: TObject);
  290. begin
  291.      if IsActiveSession then
  292.      begin
  293.         MXMessage2.Action:= ACTION_FORWARD;
  294.         MXMessage2.Action:= ACTION_SENDMSG;
  295.         If MXMessage2.ErrorNum <> 0 Then
  296.         begin
  297.             Application.MessageBox ('Unable to Send Message',
  298.                                    'Mail eXtension v1.51',
  299.                                    MB_ICONSTOP);
  300.         end;
  301.      end;
  302.  
  303. end;
  304.  
  305. procedure TDemoForm.btnSendClick(Sender: TObject);
  306. begin
  307.      if IsActiveSession then
  308.      begin
  309.         MXMessage2.Action:= ACTION_NEW;
  310.         MXMessage2.Action:= ACTION_SENDMSG;
  311.         If MXMessage2.ErrorNum <> 0 Then
  312.         begin
  313.             Application.MessageBox ('Unable to Send Message',
  314.                                    'Mail eXtension v1.51',
  315.                                    MB_ICONSTOP);
  316.         end;
  317.      end;
  318. end;
  319.  
  320. end.
  321.